﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace JinfuyuanProject.Controllers
{
    public class DataBackupController : Controller
    {
        // GET: DataBackup
        public ActionResult Index()
        {
            // 获取D:\Backup\路径下的所有备份文件
            string backupDirectory = @"D:\Backup\";
            string[] backupFiles = Directory.GetFiles(backupDirectory, "*.bak"); // 获取所有.bak文件

            // 将文件名传递到视图
            var fileNames = backupFiles.Select(file => Path.GetFileName(file)).ToList();

            return View(fileNames);
        }
        public ActionResult Download(string fileName)
        {
            // 备份文件所在路径
            string backupDirectory = @"D:\Backup\";
            string filePath = Path.Combine(backupDirectory, fileName);

            // 确保文件存在
            if (System.IO.File.Exists(filePath))
            {
                // 返回文件内容
                return File(filePath, "application/octet-stream", fileName);
            }
            else
            {
                return HttpNotFound("File not found");
            }
        }
    }
}